﻿function formatField(datetime, dateformat, timeformat) {
    var content = "";
    var sanitizeddate = $(datetime).text();

    if (Date.isValid(sanitizeddate, dateformat)) {
        var parseddate = Date.parseString(sanitizeddate, dateformat);

        content = "<span data-livestamp='" + (parseddate.getTime() / 1000) + "'></span>";
    }
    else {
        if (Date.isValid(sanitizeddate, dateformat + " " + timeformat)) {
            var parseddate = Date.parseString(sanitizeddate, dateformat + " " + timeformat);

            content = "<span data-livestamp='" + (parseddate.getTime() / 1000) + "'></span>";
        }
        else {
            if (sanitizeddate != null && sanitizeddate.trim() != "") {
                content = "Date parse error";
            }
        }
    }

    document.write("<div style='display:block'>");
    document.write("<div style='white-space:nowrap'>" + content + "</div>");
    document.write("</div>");
}